package so.ifl.commons.tools;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import so.ifl.vo.OnlineExamVo;


/**
 * @author aaron.lu(luzhiyuan) E-mail:atyuan.lu@gmail.com
 * @since Jun 16, 2010 2:29:09 PM
 */
public class SystemUtil {
	
	/**
	 * 获取初始化管理员信息
	 * create by aaron.lu
	 * create at 2012-1-11 上午9:22:17
	 * <mailto: atyuan.lu@gmail.com>
	 * @param companyId
	 * @return
	 *
	 */
	static public Map<String, Object> getInitAdmin(Integer companyId){
		Map<String, Object> adminVo = new HashMap<String, Object>(); 
		adminVo.put("company_id", companyId);
		adminVo.put("account_login_name_", "admin");
		adminVo.put("account_pwd_", MD5.getMD5("admin"));//初始密码
		adminVo.put("account_owner_", "IFL@TECH");
		adminVo.put("account_tel_", "13929867583");
		adminVo.put("account_email_", "atyuan.lu@gmail.com");
		adminVo.put("account_note_", "init_admin");
		adminVo.put("is_do", 1);
		return adminVo;
	}
	
	/**
	 * 获取初始公司信息
	 * create by aaron.lu
	 * create at 2012-1-10 下午4:03:58
	 * <mailto: atyuan.lu@gmail.com>
	 * @return
	 *
	 */
	static public Map<String, Object> getIFLInfo(){
		Map<String, Object> companyInfo = new HashMap<String, Object>();
		companyInfo.put("company_bm_", "IFL");
		companyInfo.put("company_name_", "恒益数据");
		companyInfo.put("company_address_", "--");
		companyInfo.put("company_linkman_", "--");
		companyInfo.put("company_contact_", "--");
		companyInfo.put("company_tel_", "--");
		companyInfo.put("company_email_", "atyuan.lu@gmail.com");
		companyInfo.put("is_do_", 1);
		companyInfo.put("company_active_date_", new Date());
		companyInfo.put("allow_studuent_", 1000000);
		companyInfo.put("company_ext_", "INIT_COMPANY");
		companyInfo.put("company_abridge_", "IFL");
		
		return companyInfo;
	} 
	
	/**
	 * 获取公司名
	 * create by aaron.lu
	 * create at 2013-8-9 下午9:43:41
	 * <mailto: atyuan.lu@gmail.com>
	 * @param code
	 * @return
	 *
	 */
	static public String getCompany(String code){
		Integer temp;
		String result;
		
		try {
			temp = new Integer(code);
		} catch (Exception e) {
			temp = 0;
		}
		
		switch (temp) {
		case 1:
			result =  "港龙驾校";
			break;
		case 2:
			result = "港信驾校";
			break;
		case 3:
			result = "港弘驾校";
			break;
		case 4:
			result = "骏邦驾校";
			break;
		default:
			result = "";
			break;
		}
		
		return result;
	}
	
	static public String onlineExamHTML(OnlineExamVo onlineExamVo){
		if (null != onlineExamVo) {
			StringBuffer s = new StringBuffer();
			String imgHTML = "";
			if (StringHelper.isNotEmpty(onlineExamVo.getOnlineExamImg())) {
				imgHTML = "<img src=\"./resource/exam/img/" + onlineExamVo.getOnlineExamSubject() + "/" + onlineExamVo.getOnlineExamImg() + ".jpg\" height=\"200\" width=\"240\"></img>";
			}
			s.append("<div id=\"topic\" class=\"div_topic\">" + onlineExamVo.getOnlineExamTitle() + "<br/>" + imgHTML + "</div>");
			if (onlineExamVo.getOnlineExamGroup().equals("m")) {
				if (StringHelper.isNotEmpty(onlineExamVo.getaAnswer())) {
					s.append("<p><input name=\"checkbox1\" type=\"checkbox\" value=\"A\">A、" + onlineExamVo.getaAnswer() + "</p>");
				}
				if (StringHelper.isNotEmpty(onlineExamVo.getbAnswer())) {
					s.append("<p><input name=\"checkbox1\" type=\"checkbox\" value=\"B\">B、" + onlineExamVo.getbAnswer() + "</p>");
				}
				if (StringHelper.isNotEmpty(onlineExamVo.getcAnswer())) {
					s.append("<p><input name=\"checkbox1\" type=\"checkbox\" value=\"C\">C、" + onlineExamVo.getcAnswer() + "</p>");
				}
				if (StringHelper.isNotEmpty(onlineExamVo.getdAnswer())) {
					s.append("<p><input name=\"checkbox1\" type=\"checkbox\" value=\"D\">D、" + onlineExamVo.getdAnswer() + "</p>");
				}
				
				s.append("<p><input id=\"sub\" type=\"button\" value=\"提交\">");
			}else{
				if (StringHelper.isNotEmpty(onlineExamVo.getaAnswer())) {
					s.append("<p><input name=\"radio1\" type=\"radio\" value=\"A\">A、" + onlineExamVo.getaAnswer() + "</p>");
				}
				if (StringHelper.isNotEmpty(onlineExamVo.getbAnswer())) {
					s.append("<p><input name=\"radio1\" type=\"radio\" value=\"B\">B、" + onlineExamVo.getbAnswer() + "</p>");
				}
				if (StringHelper.isNotEmpty(onlineExamVo.getcAnswer())) {
					s.append("<p><input name=\"radio1\" type=\"radio\" value=\"C\">C、" + onlineExamVo.getcAnswer() + "</p>");
				}
				if (StringHelper.isNotEmpty(onlineExamVo.getdAnswer())) {
					s.append("<p><input name=\"radio1\" type=\"radio\" value=\"D\">D、" + onlineExamVo.getdAnswer() + "</p>");
				}
			}
			
			s.append("<h4><span>答案：<span class=\"answer_this_tip\">" + onlineExamVo.getOnlineExamRightAnswer() + " 解释：" + onlineExamVo.getOnlineExamTips() + "</span></span></h4>");
			
			if(onlineExamVo.getOnlineExamSubject().equals("1")){
				if (onlineExamVo.getOnlineExamId() != 468) {
					s.append("<button type=\"button\" onclick=\"window.location.href=\'./DoExam.do?ex=" + onlineExamVo.getOnlineExamSubject() + "s&n=" + (onlineExamVo.getOnlineExamId().intValue() - 1) + "\'\">上一题</button>");
				}
				if (onlineExamVo.getOnlineExamId() != 1361) {
					s.append("<button type=\"button\" onclick=\"window.location.href=\'./DoExam.do?ex=" + onlineExamVo.getOnlineExamSubject() + "s&n=" + (onlineExamVo.getOnlineExamId().intValue() + 1) + "\'\">下一题</button>");
				}
			}
			
			if (onlineExamVo.getOnlineExamSubject().equals("4")) {
				if (onlineExamVo.getOnlineExamId() != 1) {
					s.append("<button type=\"button\" onclick=\"window.location.href=\'./DoExam.do?ex=" + onlineExamVo.getOnlineExamSubject() + "s&n=" + (onlineExamVo.getOnlineExamId().intValue() - 1) + "\'\">上一题</button>");
				}
				if (onlineExamVo.getOnlineExamId() != 467) {
					s.append("<button type=\"button\" onclick=\"window.location.href=\'./DoExam.do?ex=" + onlineExamVo.getOnlineExamSubject() + "s&n=" + (onlineExamVo.getOnlineExamId().intValue() + 1) + "\'\">下一题</button>");
				}
			}
			
			
			
			return s.toString();
		}
		
		return "";
	}
	
	
}
